package com.cssl.controller;

import cn.dev33.satoken.exception.NotLoginException;
import com.cssl.domain.dto.UserAccountDto;
import com.cssl.domain.dto.UsersDto;
import com.cssl.domain.dto.WeiXinLoginDto;
import com.cssl.domain.dto.WeiXinRegistryByPhoneDto;
import com.cssl.openFeign.UsersFeignClient;
import com.cssl.util.InfoCode;
import com.cssl.util.MD5Util;
import com.cssl.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/users")
@Api(value = "用户接口", tags = "用户相关操作")
public class UserController {
    @Autowired
    private UsersFeignClient client;


    /**
     * 发送短信接口(复制原本的接口)
     * @param req
     * @return
     */
    @PostMapping("/sendMess")
    @ApiOperation(value = "手机验证码发送",notes = "传入手机号")
    public Result sendMess(@RequestBody Map<String, Object> req) {
        Result result = client.sendMess(req);
        return result;
    }


    /**
     * 手机号注册并登录
     *
     * @param dto
     * @return user对象和saToken
     */
    @PostMapping("/weiXinRegisterByPhone")
    @ApiOperation("手机号注册并登录")
    public Result weiXinRegisterByPhone(@RequestBody WeiXinRegistryByPhoneDto dto) {
        System.out.println(dto);
        //查询手机号是否被注册过
        return client.weiXinRegisterByPhone(dto);
    }

    /**
     * 用户名,密码登录
     *
     * @param map 接收的参数 1.username 2.password 3.code
     * @return
     */
    @PostMapping("/weiXinLoginByPwd")
    @ApiOperation("用户名,密码登录")
    public Result weiXinLoginByPwd(@RequestBody Map map) {
        return client.weiXinLoginByPwd(map);
    }

    @PostMapping("/test")
    public Integer test() {
        client.test();
        return 1;
    }

    @GetMapping("/test2")
    public String test2() {
        System.out.println("jing1fdsf");
        return "243234";
    }

    /**
     * 重置密码
     *
     * @param map 1.phone 2.yzm 3.password
     *            验证码错误返回状态码422
     *            密码与原密码一致返回403
     *            修改失败返回400
     *            修改成功200,true
     * @return
     */
    @PostMapping("/resetPassword")
    @ApiOperation(value = "重置密码",notes = "传入手机号,验证码,密码")
    public Result resetPassword(@RequestBody Map<String, Object> map) {
        return client.resetPassword(map);
    }

    /**
     * 微信登录
     *
     * @param weiXinLoginDto 接收code
     * @return code错误和openId为空返回403
     * 没有此人返回204
     * 请求成功返回200 saToken , user
     */
    @PostMapping("/weiXinLogin")
    @ApiOperation("微信登录")
    public Result weiXinLogin(@RequestBody WeiXinLoginDto weiXinLoginDto) {
        return client.weiXinLogin(weiXinLoginDto);
    }

    @PostMapping("/usersList")
    @ApiOperation("用户集合")
    public Result getUsersList(@RequestBody UsersDto usersDto) {
        return client.getUsersList(usersDto);
    }

    @PostMapping("/approveAgency")
    @ApiOperation("更行状态")
    public Result UpdateStatus(@RequestBody UserAccountDto userAccountDto) {
        return client.UpdateStatus(userAccountDto);
    }

    @PostMapping("/userProxy")
    public Result userProxy(@RequestBody Map<String,Object> map){
       return client.userProxy(map);
    }

    /**
     * 清除用户全部历史搜索记录
     * @return
     */
    @PostMapping("/deleteHistory")
    @ApiOperation("清除用户搜索历史记录")
    public Result deleteHistory(){
       return client.deleteHistory();
    }

    @PostMapping("/collectTrueOrFalse")
    @ApiOperation(value = "用户收藏商品",notes = "接收type(是否取消收藏),valueId商品id")
    public Result collectTrueOrFalse(@RequestBody Map map){
        return  client.collectTrueOrFalse(map);
    }

}
